import cv2

def main():
    # RTSP视频流地址
    rtsp_url = "rtsp://admin:abcd1234@192.168.1.183:554//Streaming/Channels/1"

    # 创建视频捕捉对象
    cap = cv2.VideoCapture(rtsp_url)

    # 检查视频捕捉对象是否成功打开
    if not cap.isOpened():
        print("Error: Failed to open the video stream.")
        return

    # 读取并显示视频流
    while True:
        ret, frame = cap.read()
        if not ret:
            print("Error: Failed to read frame.")
            break

        # 在窗口中显示视频帧
        cv2.imshow('RTSP Video Stream', frame)

        # 按'q'键退出循环
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # 释放资源
    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()
